package model.backup.handlers;

import database.Database;
import java.sql.SQLException;
import model.backup.BackupOrderLine;

/**
 * Denne klasse bruges til at hente al data i bs_order_line og returnere det
 * @author junjie
 */
public abstract class BackupOrderLineHandler {
    
    /**
     * Henter alle rækker i bs_order_line og returnerer et BackupOrderLine[] model
     * @return BackupOrderLine[]
     * @throws ClassNotFoundException
     * @throws SQLException 
     */
    public static BackupOrderLine[] getBackupOrderLines() throws ClassNotFoundException, SQLException{
        BackupOrderLine[] backupOrderLines = null;
        
        Database db = new Database();
        
         String [][] result = db.getFromDB("bs_order_line", "", "", "", "id", "amount", "unit_price", "fk_product_id", "fk_order_id");
         backupOrderLines = new BackupOrderLine[result.length];
         
         db.closeDB();
         
         for (int i = 0; i < result.length; i++) {
            backupOrderLines[i] = new BackupOrderLine(Integer.parseInt(result[i][0]), Integer.parseInt(result[i][1]), Double.parseDouble(result[i][2]), 
                                                      Integer.parseInt(result[i][3]), Integer.parseInt(result[i][4]));
            
        }
         return backupOrderLines;
    }
}
